package studio.raptor.dispatcher.scheduler.zookeeper;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 基于Zookeeper的注册中心配置
 *
 * @author jack
 * @since 1.0
 */
@Component
@ConfigurationProperties(prefix = "zk")
public class ZookeeperConfiguration {


  /**
   * 连接Zookeeper服务器的列表.
   * 包括IP地址和端口号.
   * 多个地址用逗号分隔.
   * 如: host1:2181,host2:2181
   */
  @Value("${zk.servers}")
  private String servers;

  /**
   * 命名空间.
   */
  @Value("${zk.namespace}")
  private String namespace;

  /**
   * 等待重试的间隔时间的初始值.
   * 单位毫秒.
   */
  @Value("${zk.baseSleepTimeMilliseconds: 1000}")
  private int baseSleepTimeMilliseconds;

  /**
   * 等待重试的间隔时间的最大值.
   * 单位毫秒.
   */
  @Value("${zk.maxSleepTimeMilliseconds: 3000}")
  private int maxSleepTimeMilliseconds = 3000;

  /**
   * 最大重试次数.
   */
  @Value("${zk.maxRetries: 3}")
  private int maxRetries = 3;

  /**
   * 会话超时时间.
   * 单位毫秒.
   */
  @Value("${zk.sessionTimeoutMilliseconds: 3000}")
  private int sessionTimeoutMilliseconds;

  /**
   * 连接超时时间.
   * 单位毫秒.
   */
  @Value("${zk.connectionTimeoutMilliseconds: 30000}")
  private int connectionTimeoutMilliseconds;

  /**
   * 连接Zookeeper的权限令牌.
   * 缺省为不需要权限验证.
   */
  @Value("${zk.digest: ''}")
  private String digest;

  public String getServers() {
    return servers;
  }

  public void setServers(String servers) {
    this.servers = servers;
  }

  public String getNamespace() {
    return namespace;
  }

  public void setNamespace(String namespace) {
    this.namespace = namespace;
  }

  public int getBaseSleepTimeMilliseconds() {
    return baseSleepTimeMilliseconds;
  }

  public void setBaseSleepTimeMilliseconds(int baseSleepTimeMilliseconds) {
    this.baseSleepTimeMilliseconds = baseSleepTimeMilliseconds;
  }

  public int getMaxSleepTimeMilliseconds() {
    return maxSleepTimeMilliseconds;
  }

  public void setMaxSleepTimeMilliseconds(int maxSleepTimeMilliseconds) {
    this.maxSleepTimeMilliseconds = maxSleepTimeMilliseconds;
  }

  public int getMaxRetries() {
    return maxRetries;
  }

  public void setMaxRetries(int maxRetries) {
    this.maxRetries = maxRetries;
  }

  public int getSessionTimeoutMilliseconds() {
    return sessionTimeoutMilliseconds;
  }

  public void setSessionTimeoutMilliseconds(int sessionTimeoutMilliseconds) {
    this.sessionTimeoutMilliseconds = sessionTimeoutMilliseconds;
  }

  public int getConnectionTimeoutMilliseconds() {
    return connectionTimeoutMilliseconds;
  }

  public void setConnectionTimeoutMilliseconds(int connectionTimeoutMilliseconds) {
    this.connectionTimeoutMilliseconds = connectionTimeoutMilliseconds;
  }

  public String getDigest() {
    return digest;
  }

  public void setDigest(String digest) {
    this.digest = digest;
  }

  @Override
  public String toString() {
    return "ZookeeperConfiguration{" +
        "servers='" + servers + '\'' +
        ", namespace='" + namespace + '\'' +
        ", baseSleepTimeMilliseconds=" + baseSleepTimeMilliseconds +
        ", maxSleepTimeMilliseconds=" + maxSleepTimeMilliseconds +
        ", maxRetries=" + maxRetries +
        ", sessionTimeoutMilliseconds=" + sessionTimeoutMilliseconds +
        ", connectionTimeoutMilliseconds=" + connectionTimeoutMilliseconds +
        ", digest='" + digest + '\'' +
        '}';
  }
}
